home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 64 / Mac Magazin CD 64.iso / Updates / FileMaker Pro Server / Web Companion / Web Companion.rsrc / HDAT_23200_FMP-IWP.js < prev    next >
Encoding:
JavaScript  |  1999-09-08  |  13.1 KB  |  534 lines

  1. /*
  2.     FMP-IWP.js
  3.     
  4.     (c) Copyright 1999 FileMaker, Inc. All rights reserved.
  5.     
  6.     Modification History:
  7.     1/14/99 KJJ    Created.
  8. */
  9.  
  10. /* Non-object functions */
  11.  
  12. function inputElementChanged(inputElement)
  13. {
  14.     if (document.editForm[inputElement.name])
  15.     {
  16.         document.editForm[inputElement.name].value = inputElement.value;
  17.     }
  18. }
  19.  
  20. function buttonsNotSupported()
  21. {
  22.     //alert("This button is not supported!");
  23. }
  24.  
  25. /* IWPImg object definition */
  26.  
  27. function IWPImg()
  28. {
  29.     this.old        =    new Image();
  30.     this.btnR        =    new Image();
  31.     this.btnP        =    new Image();
  32.     this.btnN        =    new Image();
  33.     this.btnCR        =    new Image();
  34.     this.btnR.src    =    "btnR_over.gif";
  35.     this.btnP.src    =    "btnP_over.gif";
  36.     this.btnN.src    =    "btnN_over.gif";
  37.     this.btnCR.src    =    "btnCR_over.gif";
  38. }
  39.  
  40. /* Animate object definition */
  41.  
  42. function highlight_object(obj)
  43. {
  44.     this.SColor = obj.style.backgroundColor;
  45.     if (this.HColor == null)
  46.         //this.HColor = document.styleSheets(0).rules(0).style.backgroundColor;
  47.         if ( this.istyle == 1 )
  48.             this.HColor = this.color1;
  49.         else if ( this.istyle == 2 )
  50.             this.HColor = this.color2;
  51.         else if ( this.istyle == 3 )
  52.             this.HColor = this.color3;
  53.         else if ( this.istyle == 4 )
  54.             this.HColor = this.color4;
  55.         else if ( this.istyle == 6 )
  56.             this.HColor = this.color5;
  57.         else if ( this.istyle == 7 )
  58.             this.HColor = this.color6;
  59.         else
  60.             this.HColor = this.defColor;
  61.     obj.style.backgroundColor = this.HColor;
  62. }
  63.  
  64. function restore_color(obj)
  65. {
  66.     obj.style.backgroundColor = this.SColor;
  67. }
  68.  
  69. function swap_image(name)
  70. {
  71.     this.img.old.src = document[name].src;
  72.     document[name].src = this.img[name].src;
  73. }
  74.  
  75. function restore_image(name)
  76. {
  77.     document[name].src = this.img.old.src;
  78. }
  79.  
  80. function Animate(color)
  81. {
  82.     this.img            =    new IWPImg();
  83.     this.on                =    highlight_object;
  84.     this.off            =    restore_color;
  85.     this.swap            =    swap_image;
  86.     this.restore        =    restore_image;
  87.     this.HColor            =    null;
  88.     this.SColor            =    this.HColor;
  89.     this.istyle            =    color;
  90.     this.color1            =    "#FFCC66";
  91.     this.color2            =    "#333300";
  92.     this.color3            =    "#9999CC";
  93.     this.color4            =    "#999999";
  94.     this.color5            =    "#FFCC66";
  95.     this.color6            =    "#C1C185";
  96.     this.defColor        =    "#FFFFFF";
  97. }
  98.  
  99. /* RangeObj object definition */
  100.  
  101. function update_range(input,wantRange)
  102. {
  103.     if ( wantRange == true )
  104.     {
  105.         beg = this.iskip + 1;
  106.         if ( this.icount < beg )
  107.             beg = this.icount;
  108.         end = this.imax + this.iskip;
  109.         if ( this.icount < end )
  110.             end = this.icount;
  111.         if ( this.ifound < (end - beg + 1) )
  112.             end = beg + this.ifound - 1;
  113.         input.elements[this.eName].value = beg + this.delim + end;
  114.     }
  115.     else
  116.         input.elements[this.eName].value = this.irecnum;
  117. }
  118.  
  119. function find_range(form,input,isRange)
  120. {
  121.     var gerpy = 1;
  122.     
  123.     if (isRange == true )
  124.     {
  125.         if (document.charset == "x-sjis")
  126.         {
  127.             segments = escape(input.elements[this.eName].value);
  128.             if ( segments.indexOf(this.jdelim) > -1 )
  129.                 segments = segments.split(this.jdelim);
  130.             else
  131.                 segments = segments.split(this.delim);
  132.             for ( var i = 0; i < segments.length; ++i )
  133.                 segments[i] = this.normalize(unescape(segments[i]));
  134.         }
  135.         else
  136.             segments = input.elements[this.eName].value.split(this.delim);
  137.         if ( parseInt(segments[0]).toString() != "NaN" )
  138.         {
  139.             form.elements[this.skip].value = segments[0] - 1;
  140.             if ( parseInt(segments[1]).toString() != "NaN" )
  141.                 gerpy = segments[1] - form.elements[this.skip].value;
  142.             if ( gerpy > 0 )
  143.             {
  144.                 form.elements[this.max].value = gerpy;
  145.                 form.submit();
  146.             }
  147.             else
  148.                 this.update(input,true);
  149.         }
  150.         else
  151.             this.update(input,true);
  152.     }
  153.     else
  154.     {
  155.         gerpy = this.normalize(input.elements[this.eName].value);
  156.         if ( parseInt(gerpy).toString() != "NaN" )
  157.         {
  158.             gerpy = parseInt(gerpy) - 1;
  159.             if ( gerpy >= 0 )
  160.             {
  161.                 form.elements[this.skip].value = gerpy;
  162.                 form.elements[this.max].value = 1;
  163.                 form.submit();
  164.             }
  165.             else
  166.                 this.update(input,false);
  167.         }
  168.         else
  169.             this.update(input,false);
  170.     }
  171.     return false;
  172. }
  173.  
  174. function normalize_number(str)
  175. {
  176.     var newStr = "";
  177.     if (document.charset == "x-sjis")
  178.     {
  179.         str = escape(str);
  180.         for ( var i = 0; i < str.length; i++ )
  181.         {
  182.             if     ( (i != str.length - 1) && (str.charAt(i) == "%") )
  183.             {
  184.                 newStr += this.convertJ(str.substring(i, i + 6));
  185.                 i += 5;
  186.             }
  187.             else
  188.                 newStr += str.charAt(i);
  189.         }
  190.     }
  191.     else
  192.         newStr = str;
  193.     return newStr;
  194. }
  195.  
  196. function convert_j_num(num)
  197. {
  198.     if (num == "%uFF10")
  199.         return "0";
  200.     else if (num == "%uFF11")
  201.         return "1";
  202.     else if (num == "%uFF12")
  203.         return "2";
  204.     else if (num == "%uFF13")
  205.         return "3";
  206.     else if (num == "%uFF14")
  207.         return "4";
  208.     else if (num == "%uFF15")
  209.         return "5";
  210.     else if (num == "%uFF16")
  211.         return "6";
  212.     else if (num == "%uFF17")
  213.         return "7";
  214.     else if (num == "%uFF18")
  215.         return "8";
  216.     else if (num == "%uFF19")
  217.         return "9";
  218.     else
  219.         return "0";
  220. }
  221.  
  222. function RangeObj(obj)
  223. {
  224.     this.delim        =    "-";
  225.     this.eName        =    "range";
  226.     this.jdelim        =    "%u30FC";
  227.     this.max        =    "-max";
  228.     this.skip        =    "-skip";
  229.     this.icount        =    parseInt(obj.vcount);
  230.     this.ifound        =    parseInt(obj.vfound);
  231.     this.imax        =    parseInt(obj.vmax);
  232.     this.irecnum    =    parseInt(obj.vrecnum);
  233.     this.iskip        =    parseInt(obj.vskip);
  234.     this.convertJ    =    convert_j_num;
  235.     this.normalize    =    normalize_number;
  236.     this.show        =    find_range;
  237.     this.update        =    update_range;
  238. }
  239.  
  240. /* IWPHelp object definition */
  241.  
  242. function IWPHelp()
  243. {
  244.     this.delRec        =    "deleting";
  245.     this.edit        =    "editing";
  246.     this.form        =    "form";
  247.     this.newRec        =    "adding";
  248.     this.search        =    "searching";
  249.     this.sort        =    "sorting";
  250.     this.table        =    "table";
  251.     this.fhelp        =    "~HelpCSS.htm#";
  252. }
  253.  
  254.  
  255. /* IWPData object definition */
  256.  
  257. function IWPData()
  258. {
  259.     this.adb                =    "-db=";
  260.     this.adel                =    "-delete";
  261.     this.aerror                =    "-error=";
  262.     this.afind                =    "-find";
  263.     this.afindall            =    "-findall";
  264.     this.aformat            =    "-format=";
  265.     this.alay                =    "-lay=";
  266.     this.alop                =    "-lop=";
  267.     this.amax                =    "-max=";
  268.     this.amp                =    "&";
  269.     this.amshack            =    "-mshack=";
  270.     this.aop                =    "-op=";
  271.     this.arecid                =    "-recid=";
  272.     this.askip                =    "-skip=";
  273.     this.atok                =    "-token.0=";
  274.     this.atok1                =    "-token.1=";
  275.     this.aview                =    "-view";
  276.     this.bang                =    "!&";
  277.     this.fclassictable        =    "~TableVw.htm&";
  278.     this.fdel                =    "~DeleteCSS.htm&";
  279.     this.fedit                =    "~EditCSS.htm&";
  280.     this.ferror                =    "~Err.htm&";
  281.     this.fform                =    "~FormVwCSS.htm&";
  282.     this.fmp                =    "FMPro?";
  283.     this.fnew                =    "~NewCSS.htm&";
  284.     this.fredirf            =    "~RedirFormCSS.htm&";
  285.     this.fsearch            =    "~SearchCSS.htm&";
  286.     this.fsort                =    "~SortCSS.htm&";
  287.     this.ftable                =    "~TableVwCSS.htm&";
  288.     this.ftxttable            =    "~TableVwTxt.htm&";
  289.     this.home                =    "/";
  290.     this.one                =    "1&";
  291. }
  292.  
  293. /* IWPLinks object definition */
  294.  
  295. function IWPLinks()
  296. {
  297.     this.classic    =    new Array("fmp","adb","vdb","alay","vlayt","atok","vtok","aformat","fclassictable","vaction");
  298.     this.delBack    =    new Array("fmp","adb","vdb","alay","vlay","sort","find","alop","vlop","amax","vmax","askip","vskip","atok","vtok","atok1","vtok1","aformat","fform","afind");
  299.     this.delRec        =    new Array("fmp","adb","vdb","alay","vlay","sort","find","alop","vlop","amax","vmax","askip","vskip","atok","vtok","atok1","vtok1","aformat","fdel","amshack","vid","afind");
  300.     this.delRec2    =    new Array("fmp","adb","vdb","alay","vlay","sort","find","alop","vlop","amax","vmax","atok","vtok","atok1","vtok1","aformat","fredirf","aerror","ferror","arecid","vid","adel");
  301.     this.edit        =    new Array("fmp","adb","vdb","alay","vlay","sort","find","alop","vlop","amax","vmax","askip","vskip","atok","vtok","atok1","vtok1","aformat","fedit","afind");
  302.     this.findall    =    new Array("fmp","adb","vdb","aformat","vformat","alay","vlay","sort","amax","vmax","atok","vtok","atok1","vtok1","afindall");
  303.     this.findall2    =    new Array("fmp","adb","vdb","aformat","ftable","alay","vlay","sort","amax","vtokmax","atok","vtok","atok1","vtok1","afindall");
  304.     this.first        =    new Array("fmp","adb","vdb","aformat","vformat","alay","vlay","sort","find","alop","vlop","askip","bang","amax","vmax","atok","vtok","atok1","vtok1","afindall");
  305.     this.form        =    new Array("fmp","adb","vdb","sort","find","alop","vlop","askip","vskip","aformat","fform","aerror","ferror","alay","vlayf","amax","one","atok","vtokmax","atok1","vtok1","afind");
  306.     this.home        =    new Array("home");
  307.     this.last        =    this.first;
  308.     this.newRec        =    new Array("fmp","adb","vdb","sort","find","alop","vlop","amax","vmax","askip","vskip","aformat","fnew","alay","vlayf","atok","vtokmax","atok1","vtok1","afind");
  309.     this.next        =    this.first;
  310.     this.previous    =    this.first;
  311.     this.recLink    =    new Array("fmp","adb","vdb","sort","find","alop","vlop","aformat","fform","alay","vlayf","amax","one","askip","bang","atok","vmax","atok1","vtok1","afind");
  312.     this.search        =    new Array("fmp","adb","vdb","sort","find","alop","vlop","askip","vskip","aformat","fsearch","alay","vlays","amax","one","atok","vtokmax","atok1","vtok1","aview");
  313.     this.sort        =    new Array("fmp","adb","vdb","sort","find","alop","vlop","amax","vmax","askip","vskip","atok","vtok","atok1","vtok1","aformat","fsort","alay","vlayt","afind");
  314.     this.table        =    new Array("fmp","adb","vdb","sort","find","alop","vlop","askip","vskip","aformat","ftable","aerror","ferror","alay","vlayt","amax","vtokmax","atok","vtok","atok1","vtok1","afind");
  315.     this.textonly    =    new Array("fmp","adb","vdb","alay","vlayt","atok","vtok","aformat","ftxttable","vaction");
  316. }
  317.  
  318. /* IWPObj object definition */
  319.  
  320. function check_browser()
  321. {
  322.     var version = parseFloat(navigator.appVersion);
  323.     if (navigator.appName.indexOf("Netscape") != -1)
  324.     {
  325.         if ( version < 5.0 )
  326.         {
  327.             if ( version < 3.0 )
  328.                 this.go("classic");
  329.             else
  330.                 this.go("textonly");
  331.         }
  332.     }
  333.     else if (navigator.appName.indexOf("Microsoft") != -1)
  334.     {
  335.         if ( version < 4.0 )
  336.         {
  337.             if ( version < 3.0 )
  338.                 this.go("classic");
  339.             else
  340.                 this.go("textonly");
  341.         }
  342.     }
  343.     return false;
  344. }
  345.  
  346. function set_layout(lay)
  347. {
  348.     if ( lay != null )
  349.     {
  350.         this.data.vtok1 = escape(lay) + this.data.amp;
  351.         this.data.vlayf = this.data.vtok1;
  352.         var url = this.build("form");
  353.         window.location=url;
  354.     }
  355. }
  356.  
  357. function build_url(code)
  358. {
  359.     var url = "";
  360.     if ( code == this.ctoggle )
  361.     {
  362.         if ( this.data.vformat.toLowerCase().indexOf(this.ohelp.table) > -1 )
  363.             key = this.links[this.ohelp.form];
  364.         else
  365.             key = this.links[this.ohelp.table];
  366.     }
  367.     else
  368.         key = this.links[code];
  369.     for ( i in key )
  370.         url += this.data[key[i]];
  371.     url = this.local(url);
  372.     return url;
  373. }
  374.  
  375. function set_location(code,skip)
  376. {
  377.     if ( this.data.vtok1 != this.data.amp )
  378.         this.data.vlayf = this.data.vtok1;
  379.     var url = this.build(code);
  380.     if (code == this.cfirst)
  381.         skip = 0;
  382.     else if (code == this.clast)
  383.         skip = range.icount - range.imax;
  384.     else if (code == this.cprev)
  385.         skip = range.iskip - range.imax;
  386.     else if (code == this.cnext)
  387.     {
  388.         skip = range.iskip;
  389.         if ( range.iskip + range.imax < range.icount )
  390.             skip += range.imax;
  391.     }
  392.     url = this.insert(url,skip);
  393.     window.location=url;
  394. }
  395.  
  396. function open_help(code)
  397. {
  398.     var anchor = this.ohelp[code];
  399.     var url = this.local(this.ohelp.fhelp);
  400.     win = window.open("","","top=20,left=20,height=460,width=620,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,");
  401.     win.location = url + anchor;
  402. }
  403.  
  404. function make_obj(obj,n1,v1,n2,v2)
  405. {
  406.     n1 = this.tObj(n1);
  407.     v1 = this.tObj(v1);
  408.     n2 = this.tObj(n2);
  409.     v2 = this.tObj(v2);
  410.     if ( this.data[obj] == null )
  411.         this.data[obj] = new String();
  412.     if ( typeof v1 == "object" )
  413.     {
  414.         for ( i in v1 )
  415.         {
  416.             if ( typeof n1 == "object" )
  417.                 this.data[obj] += n1[i] + v1[i];
  418.             else
  419.                 this.data[obj] += n1 + v1[i];
  420.             if ( typeof n2 == "object" )
  421.                 this.data[obj] += n2[i] + v2[i];
  422.             else
  423.                 this.data[obj] += n2 + v2[i];
  424.         }
  425.     }
  426.     else
  427.     {
  428.         if ( v1 != "" )
  429.             this.data[obj] = n1 + v1 + n2 + v2;
  430.     }
  431. }
  432.  
  433. function make_temp(str)
  434. {
  435.     if ( str.charAt(str.length-1) == this.delim )
  436.         str = str.substring(0, str.length-1);
  437.     if ( str.indexOf(this.delim) > -1 )
  438.         str = str.split(this.delim);
  439.     return str;
  440. }
  441.  
  442. function insert_lang(str)
  443. {
  444.     var result = "";
  445.     
  446.     if ( str.indexOf(this.delim) > -1 )
  447.     {
  448.         segments = str.split(this.delim);
  449.         if ( segments[0] != "" )
  450.             result = segments[0];
  451.         for( i = 1; i < segments.length; ++i )
  452.             result += this.getlang() + segments[i];
  453.     }
  454.     else
  455.         result = str;
  456.     return result;
  457. }
  458.  
  459. function get_lang()
  460. {
  461.     if ( this.lang == null )
  462.         this.lang = this.data.vformat.substring(0,1);
  463.     return this.lang;
  464. }
  465.  
  466. function insert_skip(str,val)
  467. {
  468.     var url = str;
  469.     if ( val != null )
  470.     {
  471.         if (val < 0)
  472.             val = 0;
  473.         if ( str.indexOf(this.sDelim) > -1 )
  474.         {
  475.             segments = str.split(this.sDelim);
  476.             url = segments[0] + val + segments[1];
  477.         }
  478.     }
  479.     return url;
  480. }
  481.  
  482. function submit_form(form)
  483. {
  484.     this.parse(form.elements[this.data.aformat.substring(0, this.data.aformat.length-1)]);
  485.     this.parse(form.elements[this.data.aerror.substring(0, this.data.aerror.length-1)]);
  486.     form.submit();
  487.     return false;
  488. }
  489.  
  490. function parse_elem(obj)
  491. {
  492.     var lang = this.getlang();
  493.     
  494.     if ( obj != null )
  495.     {
  496.         if ( obj.value.indexOf(this.delim) > -1 )
  497.         {
  498.             segments = obj.value.split(this.delim)
  499.             obj.value = lang + segments[1];
  500.         }
  501.     }
  502. }
  503.  
  504. function IWPObj()
  505. {
  506.     this.cfirst        =    "first";
  507.     this.clast        =    "last";
  508.     this.cnext        =    "next";
  509.     this.cprev        =    "previous";
  510.     this.ctoggle    =    "toggle";
  511.     this.delim        =    "~";
  512.     this.sDelim        =    "!";
  513.     this.ohelp        =    new IWPHelp();
  514.     this.data        =    new IWPData();
  515.     this.build        =    build_url;
  516.     this.check        =    check_browser;
  517.     this.getlang    =    get_lang;
  518.     this.go            =    set_location;
  519.     this.gotolay    =    set_layout;
  520.     this.help        =    open_help;
  521.     this.insert        =    insert_skip;
  522.     this.links        =    new IWPLinks();
  523.     this.local        =    insert_lang;
  524.     this.make        =    make_obj;
  525.     this.parse        =    parse_elem;
  526.     this.submit        =    submit_form;
  527.     this.tObj        =    make_temp;
  528. }
  529.  
  530. /* Create Objects */
  531.  
  532. if ( window.iwp == null )
  533.     iwp = new IWPObj();
  534.